#!/bin/bash 

privilege_escalation="sudo "


if [ ! -d "/usr/lib/xoronos" ]; then
    cmd="$privilege_escalation mkdir /usr/lib/xoronos"
    echo "$cmd" ; eval "$cmd"
fi

if [ ! -d "/usr/lib/xoronos/py" ]; then
    cmd="$privilege_escalation mkdir /usr/lib/xoronos/py"
    echo "$cmd" ; eval "$cmd"
fi

file_path1=../build/bin/xrnconv-cli
file_path2=$(ls ../build/py | grep splitjoin)
if [ -e "$file_path1" ] && [ -e "$file_path2" ]; then
    fname="$(basename $file_path1)"
    cmd="$privilege_escalation cp $file_path1 /usr/local/bin ;"
    cmd="$cmd $privilege_escalation chmod 777 /usr/local/bin/$fname"
    echo "$cmd" ; eval "$cmd"
    cmd="$privilege_escalation cp $file_path2 /usr/lib/xoronos/py"
    echo "$cmd" ; eval "$cmd"
fi

file_path=../build/bin/xrnserver-cli
if [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /usr/local/bin"
    echo "$cmd" ; eval "$cmd"
fi

file_path=../build/bin/xrnperm-hash-cli
if [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /usr/local/bin"
    echo "$cmd" ; eval "$cmd"
fi

file_path=../build/py/xrnarchive-cli
if [ -e "$file_path" ]; then
    fname="$(basename $file_path)"
    cmd="$privilege_escalation cp $file_path /usr/local/bin ;"
    cmd="$cmd $privilege_escalation chmod 777 /usr/local/bin/$fname"
    echo "$cmd" ; eval "$cmd"
fi

file_path=../build/bin/xrntranslate-cli
if [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /usr/local/bin"
    echo "$cmd" ; eval "$cmd"
fi

file_path=../build/bin/xrngen-cli
if [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /usr/local/bin"
    echo "$cmd" ; eval "$cmd"
fi

file_path=../build/bin/xrnlib-cli
if [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /usr/local/bin"
    echo "$cmd" ; eval "$cmd"
fi

file_path=../build/bin/xrnlib-lexer-cli
if [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /usr/local/bin"
    echo "$cmd" ; eval "$cmd"
fi

file_path=../build/bin/xrnlib-128-cli
if [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /usr/local/bin"
    echo "$cmd" ; eval "$cmd"
fi

file_path=../build/bin/xrnlib-256-cli
if [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /usr/local/bin"
    echo "$cmd" ; eval "$cmd"
fi

file_path=../build/sharedlib/xrnlib-128.so
if [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /usr/lib/xoronos"
    echo "$cmd" ; eval "$cmd"
fi

file_path=../build/sharedlib/xrnlib-256.so
if [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /usr/lib/xoronos"
    echo "$cmd" ; eval "$cmd"
fi

file_path1=../build/bin/xrnserver-cli
file_path=../code/auxiliary_tools/xrnserver-cli-autocomplete.sh
if [ -e "$file_path1" ] && [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /etc/bash_completion.d"
    echo "$cmd" ; eval "$cmd"
fi

file_path1=../build/bin/xrnarchive-cli
file_path=../code/xrnarchive/xrnarchive-cli-autocomplete.sh
if [ -e "$file_path1" ] && [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /etc/bash_completion.d"
    echo "$cmd" ; eval "$cmd"
fi

file_path1=../build/bin/xrnlib-cli
file_path=./backend/xrnlib-cli-autocomplete.sh
if [ -e "$file_path1" ] && [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /etc/bash_completion.d"
    echo "$cmd" ; eval "$cmd"
fi

file_path1=../build/bin/xrnconv-cli
file_path=../code/xrnconv/xrnconv-cli-autocomplete.sh
if [ -e "$file_path1" ] && [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /etc/bash_completion.d"
    echo "$cmd" ; eval "$cmd"
fi

file_path1=../build/bin/xrngen-cli
file_path=../code/auxiliary_tools/xrngen-cli-autocomplete.sh
if [ -e "$file_path1" ] && [ -e "$file_path" ]; then
    cmd="$privilege_escalation cp $file_path /etc/bash_completion.d"
    echo "$cmd" ; eval "$cmd"
fi


file_path1=../build/py/_xrnlib256.so
file_path2=../build/py/xrnlib256.py
if [ -e "$file_path1" ] && [ -e "$file_path2" ]; then
    cmd="$privilege_escalation cp $file_path1 $file_path2 /usr/lib/xoronos/py"
    echo "$cmd" ; eval "$cmd"
fi

file_path1=../build/py/_xrnlib128.so
file_path2=../build/py/xrnlib128.py
if [ -e "$file_path1" ] && [ -e "$file_path2" ]; then
    cmd="$privilege_escalation cp $file_path1 $file_path2 /usr/lib/xoronos/py"
    echo "$cmd" ; eval "$cmd"
fi

file_path1=./source.sh
if [ -e "$file_path1" ] ; then
    cmd="cp $file_path1 $HOME/.local/xoronos"
    echo "$cmd" ; eval "$cmd"
fi

file_path1=./unsource.sh
if [ -e "$file_path1" ] ; then
    cmd="cp $file_path1 $HOME/.local/xoronos"
    echo "$cmd" ; eval "$cmd"
fi

file_path=../build/py/splitjoin.cpython*
if [ -e $file_path ] ; then
    cmd="$privilege_escalation cp $file_path /usr/lib/xoronos/py"
    echo "$cmd" ; eval "$cmd"
fi

file_path1=../archives/resources/miscellaneus/xoronos.tex
if [ -e "$file_path1" ] ; then
    if [ -d /usr/share/pandoc/data/templates ] ; then
        cmd="$privilege_escalation cp $file_path1 /usr/share/pandoc/data/templates"
        echo "$cmd" ; eval "$cmd"
    fi
fi


